<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
  <title>call_post_method (ZooomrRestAPI)</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
  <pre><span class="ruby-comment cmt"># File Zooomr.rb, line 140</span>
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">call_post_method</span>(<span class="ruby-identifier">a_method_to_call</span>, <span class="ruby-identifier">a_params</span>)
    
    <span class="ruby-identifier">a_params</span>[<span class="ruby-value str">'method'</span>]          = <span class="ruby-identifier">a_method_to_call</span>
    <span class="ruby-identifier">a_params</span>[<span class="ruby-value str">'format'</span>]          = <span class="ruby-value str">'json'</span>
    <span class="ruby-identifier">a_params</span>[<span class="ruby-value str">'nojsoncallback'</span>]  = <span class="ruby-value">1</span>
    
    <span class="ruby-identifier">api_sig</span> = <span class="ruby-identifier">create_signature</span>(<span class="ruby-identifier">a_params</span>)
    
    <span class="ruby-identifier">a_params</span>[<span class="ruby-value str">'api_sig'</span>] = <span class="ruby-identifier">api_sig</span>
    
    <span class="ruby-identifier">ascii_url</span> = <span class="ruby-value str">'http://api.zooomr.com/services/rest?'</span>
    
    <span class="ruby-identifier">a_params</span>.<span class="ruby-identifier">sort</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">ascii_url</span> <span class="ruby-operator">+=</span> <span class="ruby-value str">'&amp;'</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">key</span> <span class="ruby-operator">+</span> <span class="ruby-value str">'='</span> <span class="ruby-operator">+</span> <span class="ruby-constant">URI</span>.<span class="ruby-identifier">escape</span>(<span class="ruby-identifier">value</span>.<span class="ruby-identifier">to_s</span>) 
    <span class="ruby-keyword kw">end</span>
    
    <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;ASCII URL: &quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">ascii_url</span>
                <span class="ruby-identifier">url</span> = <span class="ruby-constant">URI</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">ascii_url</span>)
                
    <span class="ruby-identifier">req</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">post_form</span>(<span class="ruby-identifier">url</span>, <span class="ruby-identifier">a_params</span>)
       
    <span class="ruby-comment cmt"># check that we got a response</span>
    <span class="ruby-keyword kw">if</span> (<span class="ruby-keyword kw">nil</span>.<span class="ruby-identifier">eql?</span>(<span class="ruby-identifier">req</span>))
      <span class="ruby-comment cmt"># this is what we expect from a post that worked</span>
      <span class="ruby-identifier">resp_hash</span> = <span class="ruby-constant">JSON</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-value str">&quot;{\&quot;stat\&quot;: \&quot;ok\&quot;}&quot;</span>)
      
      <span class="ruby-keyword kw">return</span> <span class="ruby-constant">ZooomrResponse</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">resp_hash</span>)
    <span class="ruby-keyword kw">end</span>
    
    <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;RESPONSE: &quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">req</span>.<span class="ruby-identifier">body</span>

    <span class="ruby-identifier">resp_hash</span> = <span class="ruby-constant">JSON</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">req</span>.<span class="ruby-identifier">body</span>)
    <span class="ruby-keyword kw">return</span> <span class="ruby-constant">ZooomrResponse</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">resp_hash</span>)
        <span class="ruby-keyword kw">end</span></pre>
</body>
</html>